/*************************************************************************
	> File Name: P1506.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-02-18 16:34:31
 ************************************************************************/
#include <iostream>
using namespace std;

#define MAX_N 500
int grid[MAX_N + 5][MAX_N + 5];
int n, m;
int dir[4][2] = {
    {1, 0}, {-1, 0}, {0, 1}, {0, -1}
};

void dfs(int x, int y) {
    if (x < 0 || x > n + 1 || y < 0 || y > m + 1) return;
    if (grid[x][y]) return ;
    grid[x][y] = 2;
    for (int k = 0; k < 4; k++) {
        int dx = x + dir[k][0];
        int dy = y + dir[k][1];
        dfs(dx, dy);
    }
    return ;
}

int main() {
    cin >> n >> m;
    char ch;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> ch;
            if (ch == '0') grid[i][j] = 0;
            else grid[i][j] = 1;
        }
    }
    dfs(0, 0);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (grid[i][j] != 0) continue;
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}
